#include <iostream>
using namespace std;
class A {
static int i;	

public:
	int ind;
	A(){
		i++;
		ind=i;
		cout << "Constructing an A object" << endl;
	}

// private:  // the destructor must be public
~A(){
	cout << "deleting the " << ind << "th A object" << endl;
}

};

A& getA(){
	return *(new A);
}


// change value of a
A& incA(A& a){
		a.ind++;
		return a;
}

int A::i=0;

int main () {

	A& a=getA(),b;
	//A c=a; // then no need to free a
	//A &d=a;
	cout << "b: " << b.ind << endl;
	cout << "a: " << a.ind << endl;
	incA(a).ind=15;

	cout << "a: " << a.ind << endl;
	// delete (&b); // cause an error, since the system is going to free again the system
	delete (&a); // must delete manually
	return 0;
}
